package zzk.gwxer.tttttt.hanlan.ding.ui.screen

import android.content.Context
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import zzk.gwxer.tttttt.hanlan.ding.ui.component.NumberPicker
import zzk.gwxer.tttttt.hanlan.ding.ui.component.NumberPickerDefaults
import zzk.gwxer.tttttt.hanlan.ding.vm.MainViewModel

@Composable
fun SettingDialog(
    viewModel: MainViewModel,
    onDismiss: () -> Unit,
) {
    var totalPlayer = viewModel.totalPlayer.collectAsState()
    var time = viewModel.time.collectAsState()

    Dialog(
        onDismissRequest = onDismiss,
        properties = DialogProperties(
            dismissOnBackPress = true,
            dismissOnClickOutside = true
        )
    ) {
        Surface(
            modifier = Modifier
                .wrapContentSize()
                .padding(16.dp),
            shape = RoundedCornerShape(8.dp)
        ) {
            Column(modifier = Modifier.padding(16.dp)) {
                Row(
                    verticalAlignment = Alignment.CenterVertically,
                    modifier = Modifier.fillMaxWidth()
                ) {
                    Text("人数:")
                    NumberPicker(
                        value = totalPlayer.value,
                        onValueChange = { viewModel.updateTotalPlayer(it) },
                        minValue = 2,
                        maxValue = 4,
                        step = 1,
                        colors = NumberPickerDefaults.colors(
                            enabledColor = Color(0xFF6200EE),
                            textColor = Color(0xFF000000)
                        )
                    )
                }

                Row {
                    Text("思考时间:")
                    NumberPicker(
                        value = time.value,
                        onValueChange = { viewModel.updateTime(it) },
                        minValue = 5,
                        maxValue = 60,
                        step = 1,
                        colors = NumberPickerDefaults.colors(
                            enabledColor = Color(0xFF6200EE),
                            textColor = Color(0xFF000000)
                        )
                    )
                }
            }
        }
    }
}